<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .containner{
            width: 200px;
            height: 200px;
            overflow-y: scroll;
        }
        .content{
            width: 200px;
            height:1000px;
            background-color: aqua;
        }
    </style>
</head>
<body>
    <div class="containner" id="box">
        <div class="content"></div>
    </div>
</body>
<script>
   /*  document.getElementById("box").addEventListener("scroll",function(e){
        console.log("滚动",e);
    });
 */
    //防抖
    function debounce(fn,ms){
        let timer = null;
        return function(){
            if(timer){
                clearTimeout(timer);
                timer = null;
            }
            timer = setTimeout(fn,ms);
        }
    }
    /* document.getElementById("box").addEventListener("scroll",debounce(function(){
        console.log("滚动");
    },1000)); */

    //节流
    function throttle(fn,ms){
        let vaild = true;
        return function(){
            if(vaild){
                vaild = false;
                // console.log(this);
                setTimeout(function(){
                    vaild = true;
                    fn.call(this);
                },ms)
            }
        }
    }

    document.getElementById("box").addEventListener("scroll",throttle(function(){
        console.log("滚动");
    },1000));
</script>
</html>